﻿// -----------------------------------------------------------------------
// <copyright file="PhuongXa.cs" company="VDC" author="Nguyễn Quyết">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITY
{
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    ///     Class PhuongXa.cs
    /// </summary>
    public class PhuongXa
    {
        /// <summary>
        /// Gets or sets the IdPhuongXa.
        /// </summary>
        /// <value>
        /// The IdPhuongXa.
        /// </value>
        public int IdPhuongXa { get; set; }

        /// <summary>
        /// Gets or sets the IdQuanHuyen.
        /// </summary>
        /// <value>
        /// The IdQuanHuyen.
        /// </value>
        public int IdQuanHuyen { get; set; }

        /// <summary>
        /// Gets or sets the MaPhuongXa.
        /// </summary>
        /// <value>
        /// The MaPhuongXa.
        /// </value>
        public string MaPhuongXa { get; set; }

        /// <summary>
        /// Gets or sets the TenPhuongXa.
        /// </summary>
        /// <value>
        /// The TenPhuongXa.
        /// </value>
        public string TenPhuongXa { get; set; }

        /// <summary>
        /// Gets or sets the Id Tinh thanh
        /// </summary>
        public int IdTinhThanh { get; set; }

        /// <summary>
        /// Gets or sets the tên tỉnh thành
        /// </summary>
        public string TenTinhThanh { get; set; }

        /// <summary>
        /// Gets or sets the ten quan huyen.
        /// </summary>
        /// <value>
        /// The ten quan huyen.
        /// </value>
        public string TenQuanHuyen { get; set; }

        /// <summary>
        /// Gets the quan huyen.
        /// </summary>
        /// <value>
        /// The quan huyen.
        /// </value>
        public QuanHuyen QuanHuyen
        {
            get
            {
                try
                {
                    QuanHuyen quanhuyen = null;
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneQuanHuyenGetById, this.IdQuanHuyen);
                    while (reader.Read())
                    {
                        quanhuyen = new QuanHuyen();
                        if (!reader.IsDBNull(0))
                        {
                            quanhuyen.IdQuanHuyen = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            quanhuyen.IdTinhThanh = reader.GetInt32(1);
                        }

                        if (reader.GetString(2) != null)
                        {
                            quanhuyen.MaQuanHuyen = reader.GetString(2);
                        }

                        if (reader.GetString(3) != null)
                        {
                            quanhuyen.TenQuanHuyen = reader.GetString(3);
                        }
                    }

                    reader.Close();
                    reader.Dispose();
                    return quanhuyen;
                }
                catch (SqlException ex)
                {
                    LogHelper.Instance.WriteError(ex);
                    throw;
                }
           }
        }
    }
}
